package kr.hkit.androidcomplete01.ch08;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class HandlerAccess extends Activity {
	
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d("ActivityLifeCycle", "oncreate()");
		setContentView(R.layout.ch08_handleraccess);

		TextView outText = (TextView)findViewById(R.id.text);
		SetTouchHandler(outText);
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		Log.d("ActivityLifeCycle", "onStart()");
	}

	@Override
	protected void onResume() {
		super.onResume();
		Log.d("ActivityLifeCycle", "onResume()");
	}

	@Override
	protected void onPause() {
		super.onPause();
		Log.d("ActivityLifeCycle", "onPause()");
	}

	@Override
	protected void onStop() {
		super.onStop();
		Log.d("ActivityLifeCycle", "onStop()");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Log.d("ActivityLifeCycle", "onDestroy()");
	}

	void SetTouchHandler(final TextView tv) {
		LinearLayout linear = (LinearLayout)findViewById(R.id.linear); 
		linear.setOnTouchListener(new View.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_DOWN) {
					tv.setText("Touched");
					return true;
				}
				return false;
			}
		});
	}
}